<?php

namespace app\common\model;


class MallOrderGoods extends TimeModel
{
    public function getByOrderGoodsList($id, $field = '*')
    {
        return $this->field($field)
            ->where("order_id", $id)
            ->select()
            ->toArray();
    }

    /**
     *
     * @param $value
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    protected function getGetSpecsValueAttr($value)
    {
        if (empty($value)) {
            return '';
        }
        $ids = explode("-", $value);
        $res = (new MallSpecsValue())->where('id', 'in', $ids)
            ->select()->toArray();
        return array_column($res, 'title');
    }

    protected function getGetGoodsAttr($value)
    {
        if (empty($value)) {
            return '';
        }
        //查询id
        $goods = $this->where('order_id', $value)
            ->select()
            ->toArray();
        if (empty($goods)) {
            return "";
        }else{
            return array_column('goods_name');
        }
    }

}